package com.googlecode.sparda.experiments;

import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PipedOutputStream;
import java.util.HashMap;
import java.util.Map;

import org.junit.Ignore;

@Ignore
public class ClassToType {
	
	
	private static Map<Class<? extends OutputStream>, Factory> mappa;
	
	static {
		mappa = new HashMap<Class<? extends OutputStream>, Factory>();
		mappa.put(FileOutputStream.class, new Factory() {
			@Override
			public String getName() {
				return "FileOutputStream";
			}});
		mappa.put(DataOutputStream.class, new Factory() {
			@Override
			public String getName() {
				return "DataOutputStream";
			}});
		mappa.put(PipedOutputStream.class, new Factory() {
			@Override
			public String getName() {
				return "PipedOutputStream";
			}});
	}
	
	
	public static void main(String[] args) throws Throwable {
		FileOutputStream fileOutputStream = new FileOutputStream("file.tmp");
		MulipleOutputStream a = new MulipleOutputStream(fileOutputStream);
		a.write(56);
		a.close();
		try {
			a.write(60);
		} catch (IOException e) {
			System.err.println(e.getMessage());
		}
		a = new MulipleOutputStream(new FileOutputStream(fileOutputStream.getFD()));
		a.write(126);
		a.close();
		System.out.println("fine");
//		System.out.println(mappa.get(a.delegate.getClass()).getName());
//		FileOutputStream aa;
//		PipedOutputStream p;
//		DataOutputStream d; new DataOutputStream();
//		new PipedOutputStream();
	}
	
	
} interface Factory {
	String getName();
} class MulipleOutputStream extends OutputStream {
	public final OutputStream delegate;
	
	public MulipleOutputStream(OutputStream delegate) {
		this.delegate = delegate;
	}

	@Override
	public void write(int b) throws IOException {
		delegate.write(b);
	}
	
	@Override
	public void close() throws IOException {
		delegate.close();
		super.close();
	}
}
